from django.http import JsonResponse
from django.middleware.csrf import get_token

# 返回CSRF Token
def get_csrf_token_view(request):
    csrf_token = get_token(request)
    response = JsonResponse({'csrf_token': csrf_token})
    response.headers['csrf_token'] = csrf_token
    return response